import Vue from 'vue'
import axios from 'axios'
import VueAxios from "vue-axios";
import { Message } from "element-ui";
console.log(process.env.VUE_APP_BASE_API)
console.log(process.env)
console.log("66666")

Vue.prototype.$message = Message//添加的vue的实例上this可以调用
// const service = axios.create({
//     baseURL: '/api',
//     timeout: 8000
// })
axios.defaults.baseURL = '/api';
axios.defaults.timeout = 8000;

axios.interceptors.response.use(

    response => {
        const res = response.data
        let currentUrl = window.location.pathname;
        if(res.status == 0){
            return res.data
        }else if(res.status == 10){
            if(currentUrl != '/index' && currentUrl != '/login'){
                window.location.href = '/login'
            }

        }else {
            alert(res.msg);
            this.$message.warning(res.msg);
            return Promise.reject(res);
        }
    },
    (error) => {
        let res = error.response;
        console.log(error)
        this.$message.error(res.data.message);

        return Promise.reject(error);
    }
)

Vue.use(VueAxios,axios)
